import java.util.Scanner;

public class Problem {
    static Scanner in=new Scanner(System.in);
    static int[][] a;
    public static void solve() {
        int n=in.nextInt();
        String s=in.next();
        s=' '+s+' ';
        int[] f=new int[n+2];
        for(int i=1;i<=n+1;i++) {
            f[i]=f[i-1]+(s.charAt(i)-'0');
        }
        int o=-1;
        for(int i=0;i<=n;i++){
            int l=i-f[i];
            int r=f[n]-f[i];
            if(l*2>=i&&r*2>=(n-i)){
                if(Math.abs(2*i-n)<Math.abs(2*o-n)){
                    o=i;
                }
            }
        }
        System.out.println(o);
    }
    public static void main(String[] args) {
        int t=in.nextInt();
        while(t-->0) {
            solve();
        }
    }

}